import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);
import Home from '../pages/Home'
// import Pager from '../pages/Pager'
import Cart from '../pages/Cart'
import Personal from '../pages/Personal'
import Search from '../pages/Search'
import Money from '../pages/Personal/components/Money'
import Address from '../pages/Personal/components/Address'
import Login from '../pages/Personal/components/Login'
import  AddressEdit  from '../pages/Personal/components/AddressEdit';

import Category from "../pages/Category";
import Detail from "../pages/Category/Detail";

// 重写push和replace方法
let originPush = Router.prototype.push;
let originReplace = Router.prototype.replace;

Router.prototype.push = function (location, resolve, reject) {
     (resolve && reject) ? originPush.call(this, location, resolve, reject) : originPush.call(this, location, () => { }, () => { });
}
Router.prototype.replace = function (location, resolve, reject) {
     (resolve && reject) ? originReplace.call(this, location, resolve, reject) : originReplace.call(this, location, () => { }, () => { });
}

const routes = [
    {
        name: 'home',
        path: '/home',
        component:Home,
        meta:{
          istrue:true
        },
        
        children:[ 
          {
              path:'search',
              component:Search,

          }
      ]
    },
    {
        name:'search',
        path:'/search',
        component:Search,
        meta:{ istrue:true}
    },
    {
      name: "category",
      path: "/category",
      component: Category,
      meta:{ istrue:true}
    },
    {
        path: "/detail",
        component: Detail,
        meta:{ istrue:false}
    },
    {
        name: 'cart',
        path: '/cart',
        component:Cart,
        meta:{
          istrue:true
        },
    },
    {
        name: 'personal',
        path: '/personal',
        component:Personal,
        meta:{
          istrue:true
        },
    },
    {
      name: 'money',
      path: '/money',
      component:Money,
  },
  {
    name: 'address',
    path: '/address',
    component:Address,
},
 {
  name: 'login',
  path: '/login',
  component:Login,
 },
//  修改地址
{
  name: 'addressedit',
  path: '/addressedit',
  component:AddressEdit,
 },
    {
      path: '*',
      redirect: '/home'
    }
  ];

export default new Router({
  routes,
});
